In the route of camel, messages are transmitted in the form of exchange in each node of route. Therefore, understanding the exchange structure is very important for using camel.If the exchange ID is not specified, camel sets one by default, which can be used to identify an execution of a route.MEP message exchange patt
Camel running example, camel example
This is a simple Camel example. The Code is as follows:
Public static void main (String [] args) throws Exception {// create the Camel context DefaultCamelContext camelContext = new DefaultCamelContext (); // Add a route with the paramet
Camel-style nomenclature (camel-case), also known as the Hump nomenclature, is a set of naming conventions (conventions) when writing a computer program. As its name CamelCase implies, it means mixing uppercase and lowercase letters to form the names of variables and functions. Programmers in order to their own code can be easier to communicate between peers, so more than a unified readability of the better
Camel-name-utils switches between the camel style and the underline style, and camelbakUsage
It is used to switch a string between the camper style and the underline style. It may be useless to the average person, and it may be helpful for the person who writes the orm framework.
Example:
Company_name-> companyNameAdd the following dependencies to pom. xml for Installation
Usage
@Testpublic void testCamel2
subsystem provides an integrated environment for Apache Camel and the WildFly application server. It allows you to add a Camel Routes (route) as part of the WildFly configuration. Routes can be deployed as part of a Java EE application. Java EE components can use the core APIs of Camel and multiple
The best way to develop Apache camel applications is TDD, because each component of camel is independent and testable.There are a lot of good test frameworks now, and the BDD (behavioral test Drive) with groovy Spock framework is relatively good and useful.First, we start with the simplest processor.Write Test Cases First:Package Com.github.eric.camelImport Org.apache.camel.ExchangeImport Org.apache.camel.i
app. You can use as many camelcontext as you want, and of course they need to be defined with different names.Wildfly-camel can be defined and deployed in the following 3 different ways:
Defined as part of a subsystem in standalone-camel.xml and Domain.xml;
In a support for their deployment artifact deployment, of course, this deployment artifact must contain the suffix-camel-context.xml file;
mybatis is managed by Maven, and its Pom. XML content can be viewed by downloading the sub-source code of the column. Springmvc configurations do not need to be pasted out and can be seen everywhere. Here we will focus on some configuration items in the spring and configuration files, especially the following section:
Note that the configuration of the last item, through the mybatiscomponent class, camel will know how to interact with mybatis through
("timer://foo?fixedrate=trueperiod=1000"). Process (NewProcessor () { Public voidProcess (Exchange Exchange)throwsException {exchange.getout (). Setbody (NewDate ()); }}). to ("Stream:out");//2. Configure the component or endpoint for the route. } }); //3. Add route to CamelcontextContext.settracing (true); Context.start (); //4. Start Camelcontext.Thread.Sleep (Integer.max_value);//in or
org.apache.camel.*;
Import org.apache.camel.builder.*;
public class Timerroutebuilder extends Routebuilder {
static Logger LOG = Loggerfactory.getlogger ( Timerroutebuilder.class);
public void Configure () {from
(' timer://timer1?period=1000 ')
. Process (New Processor () {public
void Process (Exchange msg) {
log.info ("Processing {}", msg);}}
);
}
That's all the need for this example, and now the compilation runs.
bash> mvn compile
bash> mvn exec:java-dexec.mainclass=org.apache
Apache camel provides integration with spring and manages camelcontext through the spring container (applicationcontext). In this way, you do not need to write code to control camelcontext initialization, start and stop. camel will be started with spring startup.
This article integrates the examples in the Apache camel framework getting started example (http://bl
of exchange.C. asynchronous Processor must know the method in which it will complete processing, asynchronous or synchronous. If the process method returns true, the synchronization is complete. If the process method returns false, the asynchronous process is complete.D. When the processor finishes processing exchange, it must call the callback. done (boolean sync) method. The sync parameter must be consistent with the return value of the process method.For a
("Amqp:queue:order"). to ("Uri:validatebean", "Uri:handlebean", "Uri:emailbean"), using the spring XML definition as follows:Route> fromURI= "Amqp:queue:order"/> Multicast> toURI= "Uri:validatebean"/> toURI= "Uri:handlebean"/> toURI= "Uri:emailbean"/> Multicast>Route>If you need to add a log after processing the order, you can rename the following ruleRoute> fromURI= "Amqp:queue:order"
Camel
Key points of this Chapter
Why use Camel
Use camel to implement the following::
Resource file. If you do not use the noop option, the file will be deleted. People who have never seen Camel under
DescriptionIn the vast desert of Africa, a group of industrious and courageous alpaca family lived. Alpaca L. Sotomon, known as the Prophet by the people, is the leader of the family, and outsiders call it "the King of the Camel." The Camel King devoted his life to maintaining the stability and harmony of the family, he had personally rate the army to crush the savage invasion of the river Crab imperialism,
During system integration, an essential task is to convert data from one format to another, and then send the converted format to the target system, here we will introduce how to use freemarker in camel for data conversion.
1. The freemarker template is as follows:
2. The corresponding Java object is as follows: each person node corresponds to a valueobject placed in the peoplelist of xmltemplateparameter.
public class XMLTemplateParameter { priva
());CSV. append (","). append (customerid. Trim ());For (string item: itemids ){CSV. append (","). append (item. Trim ());}Return CSV. tostring ();}}
The code in route is as follows:
From ("file: D:/temp/inbox1 /? Delay= 30000 "). Bean (New ordertocsvbean (). To (" file: D:/temp/outbox1 ");
Camel has a set of algorithms to choose which method to call in bean (for example, whether the method name is set thr
allowed types, but ultimately to a Java.uti.Iterator object, so that camel can traverse the individual element objects through the iterator, and then for each element object Create an Exchange object, and then set the element object to the body of the message, so that a message is decomposed for multiple copies.Aggregation, which is just the inverse process of decomposition, is merging multiple messages based on
About camel games
Camel Games was founded in 2009 and is China's first top development company officially certified by the Google market. For a long time, camel games has always relied on its leading technical background to become a world-class mobile online game developer and operator, providing top-level mobile game and entertainment products for the global wir
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.